//
//  BHCompetitionApplyGroupCell.swift
//  BigHealth
//
//  Created by 蔺百好 on 2021/6/16.
//

import UIKit

class BHCompetitionApplyGroupCell: UITableViewCell {

    @IBOutlet var groupItemArray: [UIButton]!
    
    var choseGroupActBlock:((BHCompetitionApplyGroupItemModel) -> Void)?
    
    fileprivate var currentIndex: Int = 0
    fileprivate var groupArray: [BHCompetitionApplyGroupItemModel] = []
    
    func configItem(array: [BHCompetitionApplyGroupItemModel],index: Int) {
        self.groupArray = array
        self.currentIndex = index
        
        let startIndex = index*4
        
        for (btnIndex, btn) in self.groupItemArray.enumerated() {
            let nowIndex = startIndex+btnIndex
            if nowIndex < array.count {
                btn.isHidden = false
                let model = array[nowIndex]
                btn.setTitle(model.name, for: .normal)
                btn.isSelected = model.chose
                if model.chose == true {
                    btn.addLayerCorner(2, 0.5, .color_34CE98)
                    btn.backgroundColor = .color_E2F8F0
                }else {
                    btn.addLayerCorner(2, 0.5, .color_cccccc)
                    btn.backgroundColor = .white
                }
            }else {
                btn.isHidden = true
            }
        }
    }
    
    
    @IBAction func choseGroupAct(_ sender: UIButton) {
        if sender.isSelected == true {
            return
        }
        let btnIndex = sender.tag-100
        let startIndex = self.currentIndex*4
        let nowIndex = startIndex+btnIndex
        let model = self.groupArray[nowIndex]
        model.chose = true
        self.choseGroupActBlock?(model)
    }
    
    override func awakeFromNib() {
        super.awakeFromNib()
        
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    
}
